package top.boycharse.ftp.server.common;

import java.util.ArrayList;
import java.util.List;

public class UserInfo {

    private List<User> userInfoList;

     private static UserInfo instance;

     private UserInfo() {
         userInfoList = new ArrayList<>();
         // root
         User root = new User("root","123456789");
         userInfoList.add(root);
         // wangyuyong
         User wangyuyong = new User("wangyuyong","123456789");
         userInfoList.add(wangyuyong);
     }

     public static UserInfo getInstance() {
         synchronized (UserInfo.class) {
             if (instance == null) {
                 synchronized (UserInfo.class) {
                     if (instance == null) {
                         instance = new UserInfo();
                     }
                 }
             }
         }
         return instance;
     }

    /**
     * 是否存在该用户
     * @param userName
     * @return
     */
     public boolean isExitUser(String userName) {
         for (User user : userInfoList) {
             if (user.getUserName().equals(userName)) {
                 return true;
             }
         }
         return false;
     }

     public boolean isPassConfig(String userName, String passwword) {
         for (User user : userInfoList) {
             if (user.getUserName().equals(userName) && user.getPassword().equals(passwword)) {
                 return true;
             }
         }
         return false;
     }

    public static class User{
        public String userName;
        public String password;

        public User(String userName, String password) {
            this.userName = userName;
            this.password = password;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
}
